package DataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;

import DataObjects.StandardMenuRightList;

public class UpdateStandardMenu {
	private Vector<StandardMenuRightList> menuDetails;
	private Vector<String> menuDetails1;
	private int i=0;
	private int status=0;
	
	public UpdateStandardMenu(Vector<StandardMenuRightList> menuDetail,Vector<String> menuDetail1)
	{
		
		this.menuDetails=menuDetail;
		this.menuDetails1=menuDetail1;
		
		
		
	}
	




public void saveNewStandardMenu()
{
	SQLConnection sc=new SQLConnection();
	try {
				
			PreparedStatement ps2 = sc.getConnection().prepareStatement("UPDATE  menu bm SET bm.Mname=?,bm.Mstatus=?  where bm.Mid =?;");	
			sc.getConnection().setAutoCommit(false);
			ps2.setString(1,(String) menuDetails1.get(1));
			ps2.setString(2,(String) menuDetails1.get(2));
			ps2.setString(3,(String) menuDetails1.get(0));
			ps2.executeUpdate();
			sc.getConnection().commit();
			ps2.close();
			
			PreparedStatement ps1 = sc.getConnection().prepareStatement("Delete FROM recipe_in_menu Where  Mid =? ;");	
			sc.getConnection().setAutoCommit(false);
			ps1.setString(1,(String) menuDetails1.get(0));
			ps1.executeUpdate();
			while(i<menuDetails.size())
			{
				status=0;		
				PreparedStatement ps = sc.getConnection().prepareStatement("Insert Into recipe_in_menu (Mid,Rid,isSelectable,price,rquantity) values(?,?,?,?,?);");
				ps.setString(1,(String) menuDetails1.get(0));
				ps.setInt(2, menuDetails.get(i).getRid());
				ps.setInt(3, menuDetails.get(i).getIsSelectable());
				ps.setFloat(4, menuDetails.get(i).getPrice());				
				ps.setInt(5, menuDetails.get(i).getQuantity());		
				
				ps.executeUpdate();
				
				status=1;	
				ps1.close();
				ps.close();
				i++;
		}
			
		sc.getConnection().commit();
		sc.getConnection().close();
	}
	
	catch (SQLException e) {
		// TODO Auto-generated catch block
		status=0;
		e.printStackTrace();
	}
	
	
	}





public int getStatus() {
	return status;
}





public void setStatus(int status) {
	this.status = status;
}
	

	

}
